package com.sitech.portal.server.dao.ibatis;

import com.sitech.ibnms.core.BaseIbnmsDao;
import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.PageForm;
import com.sitech.portal.server.dao.INewsDao;

import java.util.HashMap;
import java.util.List;


public class NewsDaoImpl extends BaseIbnmsDao implements INewsDao {


    @Override
    public IPage selectNewsList(HashMap map, PageForm pageForm) {
        return this.findPage("selectNewsList", map, pageForm);
    }

    @Override
    public IPage selectHisNewsList(HashMap map, PageForm pageForm) {
        return this.findPage("selectHisNewsList", map, pageForm);
    }


    @Override
    public HashMap selectNews(String id) {
        return (HashMap)querySingle("selectNews",id);
    }

    @Override
    public void insertNews(HashMap news) {
        insert("insertNews",news);
    }

    @Override
    public void insertNewsDept(String newsid, String deptid) {
        HashMap map = new HashMap();
        map.put("newsid",newsid);
        map.put("deptid",deptid);
        insert("insertNewsDept", map);
    }

    @Override
    public void insertNewsFile(String newsid, String fileid) {
        HashMap map = new HashMap();
        map.put("newsid",newsid);
        map.put("fileid",fileid);
        insert("insertNewsFile", map);
    }

    @Override
    public void deleteNews(String id) {
        delete("deleteNews",id);
    }

    @Override
    public void updateNewsStatus(String id,String loginid) {
        HashMap map = new HashMap();
        map.put("id",id);
        map.put("loginid",loginid);
        update("updateNewsStatus", map);
    }

    @Override
    public void deleteNewsDept(String id) {
        delete("deleteNewsDept",id);
    }

    @Override
    public void deleteNewsUser(String id) {
        delete("deleteNewsUser",id);
    }

    @Override
    public void insertNewsDeptUser(String newsid, String deptid) {
        HashMap map = new HashMap();
        map.put("newsid",newsid);
        map.put("deptid",deptid);
        insert("insertNewsDeptUser", map);
    }

    @Override
    public void insertNewsUser(String newsid, String userid) {
        HashMap map = new HashMap();
        map.put("newsid",newsid);
        map.put("userid",userid);
        insert("insertNewsUser", map);
    }

    @Override
    public List selectUnReadNews(String userid) {
       return query("selectUnReadNews",userid);
    }

    @Override
    public void updateReadNews(String newsid, String loginid) {
        HashMap map = new HashMap();
        map.put("newsid",newsid);
        map.put("loginid",loginid);
        delete("updateReadNews",map);
    }

    @Override
    public void saveNewsFileDb(HashMap map) {
        this.insert("saveNewsFileDb", map);
    }

    @Override
    public void deleteNewsFileRel(String newsid, String fileid) {
        HashMap map = new HashMap();
        map.put("newsid",newsid);
        map.put("fileid",fileid);
        delete("deleteNewsFileRel", map);
    }

    @Override
    public void updatePopNewsStatus(String userid, String id) {
        HashMap map = new HashMap();
        map.put("id",id);
        map.put("userid",userid);
        update("updatePopNewsStatus", map);
    }

    @Override
    public boolean canBeModify(String newsid) {
        List l = query("canBeModify", newsid);
        if(l==null || l.size()==0){
            return false;
        }
        return true;
    }
}
